//
//  index.swift
//  uiKit-demo
//
//  Created by 陈澎 on 2024/12/25.
//

import UIKit
class DemoUIPageControl: UIViewController, UITextFieldDelegate {
    let searchUI = SearchBarUI()
    let labelUI = MyLabelUI()
    let btnUI = MyButtonUI()
    let imageUI = MyImageUI()
    let textFieldUI = MyTextFieldUI()
    let switchUI = MySwitchUI()
    let pageControlUI = MyPageControlUI()
    let segmentedUI = MySegmentedUI()
    let sliderUI = MySliderUI()
    let progressUI = MyProgressUI()
    let stepUI = MyStepUI()
    // 加载视图时调用的方法
    override func loadView() {
        super.loadView()
    }
    // 加载完成
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor(white: 1, alpha: 0.8)
        
        let loading = UIActivityIndicatorView(style: .large)
        loading.center = self.view.center
        // 开始加载
        loading.startAnimating()
        self.view.addSubview(loading)
     
        // 延迟三秒展示
        Timer.scheduledTimer(withTimeInterval: 3.0, repeats: false) { timer in
            
            // 创建滚动视图
            let scrollView = UIScrollView()
            scrollView.frame = self.view.bounds
    //        scrollView.backgroundColor = .blue
            // 停止加载
            loading.stopAnimating()
            self.view.backgroundColor = UIColor.white
            self.searchUI.render(self)
            self.view.addSubview(scrollView)
            
            // 创建内容容器
            let contentView = UIView()
            contentView.frame = CGRect(x: 0, y: 100, width: self.view.frame.width, height: 2000)
    //        contentView.backgroundColor=UIColor.brown
            scrollView.addSubview(contentView)
            self.labelUI.textDemo(contentView)
            self.btnUI.btnTest(contentView, target: self.btnUI)
            self.imageUI.render(contentView)
            self.textFieldUI.render(contentView, target: self.textFieldUI)
            self.switchUI.render(contentView, target: self.switchUI)
            self.pageControlUI.render(contentView, target: self.pageControlUI)
            self.segmentedUI.render(contentView, target: self.segmentedUI)
            self.sliderUI.render(contentView, target: self.sliderUI)
            self.progressUI.render(contentView)
            self.stepUI.render(contentView, target: self.stepUI)
            let pickerViewBtn = UIButton(type: UIButton.ButtonType.system)
            pickerViewBtn.frame = CGRect(x:20, y: 1160, width: 150, height: 50)
            pickerViewBtn.backgroundColor = UIColor.purple
            pickerViewBtn.setTitle("打开pickerView", for: .normal)
            pickerViewBtn.setTitleColor(UIColor.white, for: .normal)
            // 设置边框
            pickerViewBtn.layer.borderWidth = 2
            pickerViewBtn.layer.borderColor = UIColor.white.cgColor
            // 圆角半径
            pickerViewBtn.layer.cornerRadius = 10
            pickerViewBtn.addTarget(self, action: #selector(self.goPickerView), for: .touchDown)
            contentView.addSubview(pickerViewBtn)
            scrollView.contentSize = contentView.frame.size
        }
       
    }
    // 将要布局子视图时
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
    }
    // 已经布局子视图时
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
    }
    // 界面将要展示时
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    // 界面已经出现
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
    }
    // 界面将要消失
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    }
    // 界面已经消失
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
    }
    deinit {
        print("析构方法")
    }
    // 收到内存警告时
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    @objc func goPickerView() {
        let pickerView = PickerViewController()
        navigationController?.pushViewController(pickerView, animated: true)
    }
}
